
var settingHidden=0;

//初始化导航条
function initNavbar(){
	var asetting=document.getElementById("n_asetting");
	asetting.style.display="none";
	var name = navigator.platform;
	if (name.substring(0, 6) == "iPhone" || name.substring(0, 4) == "iPod"
			|| name.substring(0, 4) == "iPad") {
		init_niphone_onclick();
	} else {
		init_nhtml_onclick();
	}
}
//点击事件监听
function init_niphone_onclick(){
	var setting=document.getElementById("n_setting");
	setting.addEventListener("touchstart", clickSetting, false);
	var index=document.getElementById("n_index");
	index.addEventListener("touchstart", clickIndex, false);
	var match=document.getElementById("n_match");
	match.addEventListener("touchstart", clickMatch, false);
	var info=document.getElementById("n_info");
	info.addEventListener("touchstart", clickInfo, false);
	var help=document.getElementById("n_help");
	help.addEventListener("touchstart", clickHelp, false);
//	var ibody=document.getElementById("ibody");
//	ibody.addEventListener("touchstart", clickHiddenSetting, false);
	var ibody=document.getElementsByTagName("body")
	ibody[0].addEventListener("touchstart", clickHiddenSetting, false);
//	var iframe=document.getElementById("iframe");
//	iframe.addEventListener("touchstart", clickHiddenSetting, false);
}
function init_nhtml_onclick(){
	var setting=document.getElementById("n_setting");
	setting.addEventListener("click", clickSetting, false);
	var index=document.getElementById("n_index");
	index.addEventListener("click", clickIndex, false);
	var match=document.getElementById("n_match");
	match.addEventListener("click", clickMatch, false);
	var info=document.getElementById("n_info");
	info.addEventListener("click", clickInfo, false);
	var help=document.getElementById("n_help");
	help.addEventListener("click", clickHelp, false);
//	var ibody=document.getElementById("ibody");
//	ibody.addEventListener("click", clickHiddenSetting, false);
	var ibody=document.getElementsByTagName("body")
	ibody[0].addEventListener("click", clickHiddenSetting, false);
//	var iframe=document.getElementById("iframe");
//	iframe.addEventListener("click", clickHiddenSetting, false);
}
//点击首页
function clickIndex(){
//	var unionId = document.getElementById("unionId").value;
//	window.location.href=ctx+"/wechat/index_servlet?unionId="+unionId+"&mathNum="+Math.random();
	selectMenu(1);

//	var iframe=document.getElementById("iframe");
//	iframe.src=ctx+"/v3/home.jsp";
	iframe.document.location.replace(ctx+"/v3/home.jsp");
}
//点击群组
function clickMatch(){
	selectMenu(2);
	
//	var iframe=document.getElementById("iframe");
	var userType=document.getElementById("userType").value;
	if(userType==0 || userType==10){
//		iframe.document.location.replace(ctx+"/v3/pedometer/match_enterprise/match_index_v3.jsp");
		iframe.document.location.replace(ctx+"/v3/pedometer/match_enterprise/match_index_new.jsp");
	}
	else{
		iframe.document.location.replace(ctx+"/v3/pedometer/match/match_index_v3.jsp");
	}
	
//	iframe.src=ctx+"/v3/pedometer/match/match_index_v3.jsp";
//	var unionId=document.getElementById("unionId").value;
//	var pedometeropenId = document.getElementById("pedometeropenId").value;
//	var weightopenId = document.getElementById("weightopenId").value;
//	window.location.href=ctx+"/wechat/v3match?unionId="+unionId+"&pedometeropenId="+pedometeropenId+"&weightopenId="+weightopenId;
}
//点击设置
function clickSetting(){
	
	selectMenu(3);
	
//	var iframe=document.getElementById("iframe");
//	iframe.src=ctx+"/v3/setting/manydevice/device_setting.jsp";
	var userType=document.getElementById("userType").value;
	var enterpriseId=document.getElementById("enterpriseId").value;
	iframe.document.location.replace(ctx+"/v3/setting/manydevice/device_setting.jsp?userType="+userType+"&&enterpriseId="+enterpriseId + "&ttt=10001");
	
	
//	var asetting=document.getElementById("n_asetting");
//	if(asetting.style.display=="none"){
//		asetting.style.display="block";
//	}else if(asetting.style.display=="block"){
//		asetting.style.display="none";
//	}
}
//点击页面隐藏设置
function clickHiddenSetting(e){
	var asetting=document.getElementById("n_asetting");
	if(e.srcElement.id!="n_setting"&&e.srcElement.id!="n_simg"){
		if(asetting.style.display=="block"){
			asetting.style.display="none";
		}
	}
}
//点击个人信息
function clickInfo(){
	selectMenu(3);
	
	window.setTimeout(timeoutInfo, 500);
	
//	var asetting=document.getElementById("n_asetting");
//	if(asetting.style.display=="none"){
//		asetting.style.display="block";
//	}else if(asetting.style.display=="block"){
//		asetting.style.display="none";
//	}
}

function timeoutInfo(){
	var iframe=document.getElementById("iframe");
	iframe.src=ctx+"/v3/weight/setting.jsp";
//	var unionId=document.getElementById("unionId").value;
//	var pedometeropenId = document.getElementById("pedometeropenId").value;
//	var weightopenId = document.getElementById("weightopenId").value;
//	window.location.href=ctx+"/wechat/v3weightsetting?unionId="+unionId+"&pedometeropenId="+pedometeropenId+"&weightopenId="+weightopenId;

}
//点击帮助
function clickHelp(){
	selectMenu(3);
	
	window.setTimeout(timeoutHelp, 500);
	
//	var asetting=document.getElementById("n_asetting");
//	if(asetting.style.display=="none"){
//		asetting.style.display="block";
//	}else if(asetting.style.display=="block"){
//		asetting.style.display="none";
//	}
	
}

function timeoutHelp(){
	var iframe=document.getElementById("iframe");
	iframe.src=ctx+"/v3/help/help.jsp";
//	var unionId=document.getElementById("unionId").value;
//	var pedometeropenId = document.getElementById("pedometeropenId").value;
//	var weightopenId = document.getElementById("weightopenId").value;
//	window.location.href=ctx+"/v3/help/help.jsp?unionId="+unionId+"&pedometeropenId="+pedometeropenId+"&weightopenId="+weightopenId;
}

function selectMenu(pageIndex){
	var n_iimg=document.getElementById("n_iimg");//首页
	var n_mimg=document.getElementById("n_mimg");//群组
	var n_simg=document.getElementById("n_simg");//设置
//	var toolbar=document.getElementById("toolbar");//主页工具条
	var navbar=document.getElementById("navbar");//导航条
	var bottombar=document.getElementById("bottombar");//群组工具条
	
	if(pageIndex==1){
		n_iimg.src=ctx+"/v3/img/v3-img/navbar_i01.png";
		n_mimg.src=ctx+"/v3/img/v3-img/navbar_i2.png";
		n_simg.src=ctx+"/v3/img/v3-img/navbar_i3.png";
//		toolbar.style.display="block";
		navbar.style.display="block";
		bottombar.style.display="none";
		document.title = "我的微动";
	}else if(pageIndex==2){
		n_iimg.src=ctx+"/v3/img/v3-img/navbar_i1.png";
		n_mimg.src=ctx+"/v3/img/v3-img/navbar_i02.png";
		n_simg.src=ctx+"/v3/img/v3-img/navbar_i3.png";
//		toolbar.style.display="none";
		navbar.style.display="block";
		bottombar.style.display="block";
		document.title = "群组";
	}else if(pageIndex==3){
		n_iimg.src=ctx+"/v3/img/v3-img/navbar_i1.png";
		n_mimg.src=ctx+"/v3/img/v3-img/navbar_i2.png";
		n_simg.src=ctx+"/v3/img/v3-img/navbar_i03.png";
//		toolbar.style.display="none";
		navbar.style.display="block";
		bottombar.style.display="none";
		document.title="设置";
	}else if(pageIndex==0){
//		toolbar.style.display="none";
		navbar.style.display="none";
		bottombar.style.display="none";
	}
	
	var iframe=document.getElementById("iframe");
//	iframe.style.display="none";
	var height=document.documentElement.clientHeight;//window.innerHeight;//screen.height;//window.screen.availHeight;//document.body.scrollHeight;//document.body.clientHeight;
//	alert(height);
//	alert(document.documentElement.clientHeight)
	if(height==0){
		height=1000;
	}
	iframe.height=height+"px";
//	iframe.width=window.innerWidth+"px";
//	alert(window.innerWidth);
//	alert(iframe.height);
}

